<?php

namespace App\Admin\Controllers;

use Encore\Admin\Form;
use App\Models\ConfigSale;
use Encore\Admin\Controllers\AdminController;

class ConfigSalesController extends AdminController
{
	protected $title = '潮人夜市配置';
	
    protected function form()
    {
        $form = new Form(new ConfigSale());
		
		$form->currency('apple_actual_price', '苹果实际价格')->symbol('￥')->default(5.00)->rules('required');
	    $form->currency('vip_price', '会员账号售价')->symbol('￥')->default(19.90)->rules('required');
	    $form->number('vip_period', '会员账号有效期/日')->default(30)->min(1)->max(31);
	    $form->number('auto_upgrade_needs_children', '升星发展下级所需')->min(0)->default(6)->rules('required');
	    $form->number('auto_upteam_needs_children', '升团队发展下级所需')->min(0)->default(10)->rules('required');

	    $form->number('one_day_vip_cards', '单日vip购卡数')->default(10);
	    
	    $form->divider();
		
		$form->currency('normal_vip_produce_apple', '普通会员产出苹果')->default(0.08)->rules('required');
		$form->currency('vip_produce_apple', '星级会员产出苹果')->default(1.0)->rules('required');
	    $form->rate('vip_one_level_brokage_percent', '一级团队分佣比例')->default(20);
	    $form->rate('vip_two_level_brokage_percent', '二级团队分佣比例')->default(7);
	    $form->rate('vip_more_level_brokage_percent', '其他等级团队分佣比例')->default(0.06);
	    $form->rate('order_own_rewards_percent', '自购返佣比例')->default(50);
	    $form->rate('order_parent_rewards_percent', '上级订单返佣比例')->default(10);

	    $form->timeRange('start_at', 'end_at', '抢购时间范围');
	    
	    $form->number('detect_days', '几天后检测');
	    $form->rate('children_order_percent', '检测购物人数比例')->default(20);
	    
	    
	    $this->formTools($form);
	    $this->formFooter($form);
	    $this->formSaved($form);
	    
        return $form;
    }
	
	protected function formTools(Form $form)
	{
		$form->tools(function (Form\Tools $tools) {
			$tools->disableList();
			$tools->disableView();
			$tools->disableDelete();
		});
	}
	
	protected function formFooter(Form $form)
	{
		$form->footer(function (Form\Footer $footer) {
			$footer->disableReset();
			$footer->disableViewCheck();
			$footer->disableCreatingCheck();
			$footer->disableEditingCheck();
		});
	}
	
	protected function formSaved(Form $form)
	{
		$form->saved(function () {
			admin_toastr('潮人夜市配置', 'success');
			return redirect(route('admin.config-sales.edit', 1));
		});
	}
}
